//*************************************************************************************
/** \file task_temperature.h
 *    This file contains a class which reads a temperature sensor. Readings from the
 *    sensor are averaged over a given period, and the average can be grabbed by a
 *    radio task to be transmitted to a base station somewhere. 
 *
 *  Revisions:
 *    \li 12-26-07 JRR Original file
 *    \li 12-30-07 JRR Corrected spelling of Fahrenheit
 *    \li 06-01-08 JRR Changed serial stuff to use base_text_serial and descendents
 */
//*************************************************************************************

/// This define prevents this file from being included more than once in a *.cc file
#ifndef _TASK_TEMPERATURE_H_
#define _TASK_TEMPERATURE_H_

#include "stl_task.h"
#include "avr_ds1822.h"

/** If this is defined, temperatures will be returned in degrees Fahrenheit; otherwise
 *  Celsius will be used. */
#define USE_FAHRENHEIT


//-------------------------------------------------------------------------------------
/** This class contains a task which reads a DS1822 temperature sensor periodically
 *  and makes the average reading available to anyone who calls its get_average()
 *  method. 
 */

class task_temperature : public stl_task
{
	protected:
		/// This is a pointer to the serial device used for debugging
		base_text_serial* the_debug_port;

		/// This is a pointer to a DS1822 temperature sensor object
		avr_ds1822* the_sensor;

		/// This is the most recently taken temperature reading
		int most_recent_reading;

		/// This is the number of temperature readins which will be taken in a cycle
		int num_readings;

		/// This is the sum of all the readings, used for averaging over time
		long sum_of_readings;

	public:
		// The constructor creates a new task object
		task_temperature (avr_ds1822*, task_timer&, time_stamp);

		// The run method is where the task actually performs its function
		char run (char);

		// This method calculates and returns the average reading since it was 
		// previously called, then restarts the averaging process
		int get_average (void);

		// This method returns the most recent temperature reading
		int get_latest (void);
};

#endif // _TASK_TEMPERATURE_H_
